package com.wdz.article.mapper.primary;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.wdz.article.entity.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 文章列表 Mapper 接口
 * </p>
 *
 * @author 吴传逞
 * @since 2020-11-04
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {
    /**
     * 模糊查询数量
     */
    int likeTitleCount(@Param("name")String name);
    /**
     * 根据关联分类id查出文章
     */
    @Select("SELECT DISTINCT d.* FROM category a RIGHT JOIN article d ON d.parent_category_id = a.id\n" +
            "            OR d.relation_category_ids like CONCAT('%',a.id,'%')\n" +
            "        WHERE a.id = #{id} limit ${pageNo},${pageSize}")
    List<Article> selectArticleByRes(@Param("id") String id, @Param("pageNo") Integer pageNo,@Param("pageSize") Integer pageSize);
    /**
     * 根据关联分类id查出文章总数
     */
    @Select("SELECT count(0) FROM category a RIGHT JOIN article d ON d.parent_category_id = a.id\n" +
            "            OR d.relation_category_ids like CONCAT('%',a.id,'%')\n" +
            "        WHERE a.id = #{id}")
    int selectArticleByResCount(@Param("id") String id);
}
